<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8" />
    <title>数据监视</title>
    <script type="text/javascript" src="../js/vue.js"></script>
</head>

<body>
    <!-- 准备好一个容器-->
    <div id="root">
        <h1>今天天气很{{isHot ? '炎热': '凉爽'}}</h1>
        <button @click="changeWeather">切换天气</button>
    </div>
</body>
<script type="text/javascript">
    Vue.config.productionTip = false
    const vm = new Vue({
        el: '#root',
        data: {
            isHot: true
        },
        methods: {
            changeWeather() {
                this.isHot = !this.isHot
            }
        },
    })

    // 对象写法
    // vm.$watch('isHot',{
    //     immediate:true,
    //     handler(n,o){
    //         console.log('isHot被人修改了',n,o)
    //     }
    // })

    // 函数写法(简写)

    vm.$watch('isHot',function (n,o) { 
        console.log('isHot被人改了',n,o)
     })
</script>

</html>